package cn.denny.designpattern.flyweight;

import java.util.HashMap;
import java.util.Map;

public class WebSiteFactory {

	private Map<String, WebSite> map = new HashMap<String, WebSite>();
	private static WebSiteFactory instance;
	private WebSiteFactory(){
		
	}
	
	public static WebSiteFactory getInstance(){
		if(instance == null){
			instance = new WebSiteFactory();
		}
		return instance;
	}
	
	public WebSite getWebSite(String key){
		WebSite site = map.get(key);
		if(site == null){
			site = new NewsWebSite(key);
			map.put(key, site);
		}
		return site;
	}
	
	public int getWebSiteCount(){
		return map.size();
	}
}
